/**
 * 扑克牌測試用例
 * 測試入口：
var test = new texasPokerTest();
var _result = test.testGetCards();	
_server.writeFile('texas.test.txt', _result, false);
 *  
 */
##include / texas / texas / data / poker.as
##include / texas / texas / event / texasPoker.as

function texasPokerTest()
{
	  /**
	 * 测试规则
	 * @access private
	 * @var array array private => 2张私牌，public => 5 张公牌，result => 测试比对正确结果，牌的定义规则：0 黑桃、1 红心、2 梅花、3 方块
	  *	 FLUSH_WAY 		 同花顺
	  *	 FOUR_OF_A_KIND	 四条
	  *	 FULL_HOUSE 		 三条加一对
	  *	 FLUSH 			 同花
	  *	 WAY 				 顺子
	  *	 TWO_TWAIN 		 两对
	  *	 TWAIN			    一对
	  *	 OFFSUIT			杂牌
	 */        
	
	this._max_cards_test = [];
	this._win_test = [];
	this._cards = [];
	var _obj_poker = new poker();
	this._cards = _obj_poker.get();
	var _i = 0;
	var _tmp_cards = { }
	/*同花順 VS 同花順*/
	_tmp_cards['private'] = ['0,A','0,K'];
	_tmp_cards['public']  = ['0,Q','0,J','0,10','0,9','0,8'];
	_tmp_cards['result']  = {
								cards:['0,A','0,K','0,Q','0,J','0,10'],
								result:'FLUSH_WAY',
								note:'同花順 VS 同花順：黑桃A 黑桃K 黑桃Q 黑桃J 黑桃10 同花顺。'
						    }
	this._max_cards_test[_i] = _tmp_cards;
	
	/*同花順 VS 同花*/
	_i++;
	_tmp_cards['private'] = ['0,A','0,K'];
	_tmp_cards['public']  = ['0,Q','0,J','0,10','1,8','0,7'];
	_tmp_cards['result']  = {
								cards:['0,A','0,K','0,Q','0,J','0,7'],
								result:'FLUSH_WAY',
								note:'同花順 VS 同花：黑桃A 黑桃K 黑桃Q 黑桃J 黑桃10 同花顺'
						    }
	this._max_cards_test[_i] = _tmp_cards;	
	
	/*同花順 VS 順子*/
	_i++;
	_tmp_cards['private'] = ['0,A','0,K'];
	_tmp_cards['public']  = ['0,Q','0,J','0,10','1,9','0,7'];
	_tmp_cards['result']  = {
								cards:['0,A','0,K','1,Q','0,J','2,10'],
								result:'FLUSH_WAY',
								note:'同花順 VS 同花：黑桃A 黑桃K 黑桃Q 黑桃J 黑桃10 同花顺。'
						    }
	this._max_cards_test[_i] = _tmp_cards;	
	//
	///*同花順 VS 三條*/
	//_i++;
	//_tmp_cards['private'] = ['0,3','0,K'];
	//_tmp_cards['public']  = ['0,Q','0,J','0,10','1,10','2,10'];
	//_tmp_cards['result']  = {
								//cards:['0,A','0,K','0,Q','0,J','0,10'],
								//result:'FLUSH_WAY',
								//note:'同花順 VS 同花：黑桃A 黑桃K 黑桃Q 黑桃J 黑桃10 同花顺。'
						    //}
	//this._max_cards_test[_i] = _tmp_cards;	
	
	
}

	texasPokerTest.prototype.testGetCards = function() {
		_obj_poker = new texasPoker();
		var _cards;
		var _all_cards = [];
		var _print_str = '';
		for (var _key in this._max_cards_test) {
			_cards = this._max_cards_test[_key];
			_private_cards = this._getCards(_cards['private']);
			_public_cards = this._getCards(_cards['public']);
			_result_cards = this._getCards(_cards['result']['cards']);	
			_max_cards = _obj_poker.getResult(_private_cards, _public_cards);			
	
			_max_cards_test_result = false;
			_all_cards[1] = _max_cards;
			var _tmp_array = { };
			_tmp_array['cards'] = _result_cards;
			_tmp_array['result'] = _cards['result']['result'];			
			_all_cards[2] = _tmp_array;			
			_last_result = _obj_poker.compare(_all_cards);
			var _winner_id =  String(_last_result[0]).split(',');		
			if (2 == _winner_id.length) {
				_max_cards_test_result = true;
			}
			_print_str += "\r\n---------------------------------";
			_print_str += '\r\n公共牌:';
			for each(var val in _public_cards){
				_print_str +=  val['label']+"["+val['suit']+"]  ";
			}
			_print_str += "\r\n玩家持有:";
			for each(var val in _private_cards){
				_print_str += val['label']+"["+val['suit']+"]  ";
			}
			_print_str += "\r\n玩家成手牌:";
			for each(var val in _max_cards['cards']){
				_print_str += val['label']+"["+val['suit']+"]  ";
			}
			
			_print_str += "\r\n贏家ID: " + _winner_id;
			if (_max_cards_test_result) {
				_print_str+="(平局)"
			}
			_print_str += "  牌型:" + _max_cards['result'] + '\r\n';
			_print_str += '結果比對:'+_cards['result']['result']+" "+_cards['result']['note']
		}
		return _print_str;
	}
	
	texasPokerTest.prototype._getCards = function(r_array) {		
		_cards_label = { '2':0, '3':1, '4':2, '5':3, '6':4, '7':5, '8':6, '9':7, '10':8, 'J':9, 'Q':10, 'K':11, 'A':12 };		
		var _new_array = Array();
		var _cards_array = [];
		for each(var _val in r_array) {
			_cards_array = _val.split(',');		
			var _k = Number(_cards_array[0]) * 13 + Number(_cards_label[String(_cards_array[1])]);
			_new_array.push(this._cards[_k]);

		}
		return _new_array;		
	}
	
	texasPokerTest.prototype.testWinResult = function() {
		_obj_poker = new texasPoker();
		
	}